package com.ctsi.djcloudmqtt.controller;

import com.ctsi.djcloudmqtt.dto.WeatherDTO;
import com.ctsi.djcloudmqtt.dto.http.DJHttpChangeAiStatusDTO;
import com.ctsi.djcloudmqtt.dto.http.DJHttpResponseParentDTO;
import com.ctsi.djcloudmqtt.dto.http.Takeoff2pointResponseDTO;
import com.ctsi.djcloudmqtt.dto.up.FlighttaskResourceGetReturnHomeDownDTO;
import com.ctsi.djcloudmqtt.dto.up.ReturnHomeDownWithDataDTO;
import com.ctsi.djcloudmqtt.dto.up.Takeoff2PointProgressUpDTO;
import com.ctsi.djcloudmqtt.mq.MqttAcceptCallback;
import com.ctsi.djcloudmqtt.mq.MqttSendClient;
import com.ctsi.djcloudmqtt.service.MqttService;
import com.ctsi.djcloudmqtt.service.WrkjService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/mqtt")
public class MqttController {

    @Resource
    private MqttSendClient mqttSendClient;

    @Resource
    private MqttService mqttService;

    @Resource
    private WrkjService wrkjService;

    @Resource
    private MqttAcceptCallback mqttAcceptCallback;

    /**
     * 手工指定主题发布
     * @param topic
     * @param message
     * @return
     */
    @GetMapping(value = "/publishTopic")
    public String publishTopic(@RequestParam("topic") String topic,@RequestParam("message") String message) {
        System.out.println("message:" + message);
        this.mqttSendClient.publish(false, topic, message);
        return  "message:" + message;
    }



    /**
     * 自定义一键起飞
     */
    @GetMapping(value = "/customTakeoff2point")
    public String customTakeoff2point() {
        return this.mqttService.customTakeoff2point(null);
    }


    /**
     * 一键起飞
     * @return
     */
    @GetMapping(value = "/takeoff2point")
    public String takeoff2point() {
        return this.mqttService.takeoff2point(null);
    }


    /**
     * 一键起飞
     *
     * @return
     */
    @GetMapping(value = "/takeoff2point_http")
    public DJHttpResponseParentDTO<Takeoff2pointResponseDTO> takeoff2point_http() {
        return this.wrkjService.takeoff2point();
    }


    /**
     * 开启/关闭无人机视频车牌ai识别
     *
     * @return
     */
    @PostMapping(value = "/changeAiStatus")
    public DJHttpResponseParentDTO changeAiStatus(DJHttpChangeAiStatusDTO djHttpChangeAiStatusDTO) {
        return this.wrkjService.changeAiStatus(djHttpChangeAiStatusDTO);
    }


    /**
     * 查询AI识别车牌结果
     *
     * @return
     */
    @GetMapping(value = "/queryPlateInfo")
    public DJHttpResponseParentDTO queryPlateInfo(@RequestParam("recordId") Long recordId) {
        return this.wrkjService.queryPlateInfo(recordId);
    }

    /**
     * 飞行控制权抢夺
     * @return
     */
    @GetMapping(value = "/flightAuthorityGrab")
    public String flightAuthorityGrab() {
        return this.mqttService.flightAuthorityGrab(null);
    }


    /**
     *负载控制抢夺权
     * @return
     */
    @GetMapping(value = "/payloadAuthorityGrab")
    public String payloadAuthorityGrab() {
        return this.mqttService.payloadAuthorityGrab(null);
    }

    /**
     * flyto 飞向目标点
     * @return
     */
    @GetMapping(value = "/fly2point")
    public String fly2point() {
        return this.mqttService.fly2point(null);
    }

    /**
     * 航线获取
     * @return
     */
    @GetMapping(value = "/flighttask_resource_get")
    public ReturnHomeDownWithDataDTO<FlighttaskResourceGetReturnHomeDownDTO> flighttaskResourceGet() {
        return this.mqttService.flighttaskResourceGet();
    }

    /**
     * 航线下发任务
     * @param bid
     * @param flightId
     * @return
     */
    @GetMapping(value = "/flighttaskPrepare")
    public String flighttaskPrepare(@RequestParam("bid")  String bid,@RequestParam("flightId") String flightId) {
        return this.mqttService.flighttaskPrepare(bid,flightId);
    }

    /**
     * 航线执行任务
     * @return
     */
    @GetMapping(value = "/flighttaskExecute")
    public String flighttaskExecute(@RequestParam("bid")  String bid,@RequestParam("flightId") String flightId) {
        return this.mqttService.flighttaskExecute(bid,flightId);
    }

    /**
     * 航线取消任务
     * @return
     */
    @GetMapping(value = "/flighttaskUndo")
    public String flighttaskUndo(@RequestParam("bid")  String bid,@RequestParam("flightId") String flightId) {
        List<String> list = new ArrayList<>();
        list.add(flightId);
        return this.mqttService.flighttaskUndo(bid,list);
    }

    /**
     * 航线暂停
     * @return
     */
    @GetMapping(value = "/flighttaskPause")
    public String flighttaskPause(@RequestParam("bid")  String bid) {
        return this.mqttService.flighttaskPause(bid);
    }

    /**
     * 航线恢复
     * @return
     */
    @GetMapping(value = "/flighttaskRecovery")
    public String flighttaskRecovery(@RequestParam("bid")  String bid) {
        return this.mqttService.flighttaskRecovery(bid);
    }


    /**
     * 一键返航
     * @return
     */
    @GetMapping(value = "/returnHome")
    public String returnHome() {
        return this.mqttService.returnHome(null);
    }

    /**
     * 喊话
     * @return
     */
    @GetMapping(value = "/speakerTtsPlayStart")
    public String speakerTtsPlayStart() {
        return this.mqttService.speakerTtsPlayStart(null);
    }

    /**
     * 停止喊话
     * @return
     */
    @GetMapping(value = "/speakerPlayStop")
    public String speakerPlayStop() {
        return this.mqttService.speakerPlayStop(null);
    }


    /**
     * 查询一键起飞进度
     * @return
     */
    @GetMapping(value = "/takeoff2pointProgress")
    public Takeoff2PointProgressUpDTO takeoff2pointProgress(@RequestParam("bid")  String bid){
        return this.mqttService.takeoff2pointProgress(bid);
    }

    /**
     * 查询天气
     * @return
     */
    @GetMapping(value = "/getWeather")
    public WeatherDTO getWeather(){
        return MqttAcceptCallback.weatherDTO;
    }



}
